/* ====================================================================
 * (#)Header: Criterias.java
 * (#)Revision: 
 * (#)Date Created: 2009-08-29
 * (#)Created By: Karol Wozniak
 * ====================================================================
 *
 * Copyright (c) 2007 karolak .  All rights reserved.
 *
 * ====================================================================
 * 
 * The software application represented here is the sole property of 
 * karolak. Its unauthorized utilization is expressly prohibited.
 * 
 * ====================================================================
 */
package com.karolak.query;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <code>Criterias</code> is ....
 * 
 * @author <a href="mailto:kwozniak@hotmail.com">Karol Wozniak</a>
 */
public class Criterias implements Serializable {

	private static final long serialVersionUID = 1L;

	private List<Criteria> entries;
	private Map<String, String> orderBy;

	public Criterias() {
		setEntries(new ArrayList<Criteria>());
		setOrderBy(new HashMap<String, String>());
	}

	public void add(String propertyName, Object value) {
		add("and", propertyName, "=", value);
	}

	public void add(String propertyName, String equalityOperator, Object value) {
		add("and", propertyName, equalityOperator, value);
	}

	public void add(String logicalOperator, String propertyName, String equalityOperator, Object value) {
		Criteria criteria = new Criteria();
		criteria.setLogicalOperator(logicalOperator);
		criteria.setPropertyName(propertyName);
		criteria.setEqualityOperator(equalityOperator);
		criteria.setValue(value);
		getEntries().add(criteria);
	}

	public void addOrderBy(String propertyName, String sortOrder) {
		getOrderBy().put(propertyName, sortOrder);
	}

	// === get/set === //
	public List<Criteria> getEntries() {
		return entries;
	}

	protected void setEntries(List<Criteria> criterias) {
		this.entries = criterias;
	}

	public Map<String, String> getOrderBy() {
		return orderBy;
	}

	protected void setOrderBy(Map<String, String> orderBy) {
		this.orderBy = orderBy;
	}
}
